package com.centit.airplanebaseinfo.service.impl;

import java.util.Date;
import java.util.Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.centit.support.database.utils.PageDesc;
 
import com.centit.framework.jdbc.service.BaseEntityManagerImpl;




import com.centit.airplanebaseinfo.po.AirplaneBaseinfo;
import com.centit.airplanebaseinfo.dao.AirplaneBaseinfoDao;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.centit.airplanebaseinfo.service.AirplaneBaseinfoManager;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
/**
 * AirplaneBaseinfo  Service.
 * create by scaffold 2020-03-13 
 * @author codefan@sina.com
 * 飞机基础信息飞机基础信息   
*/
@Service
public class AirplaneBaseinfoManagerImpl 
		extends BaseEntityManagerImpl<AirplaneBaseinfo,java.lang.String,AirplaneBaseinfoDao>
	implements AirplaneBaseinfoManager{

	public static final Log log = LogFactory.getLog(AirplaneBaseinfoManager.class);

	
	private AirplaneBaseinfoDao airplaneBaseinfoDao ;
	
	@Resource(name = "airplaneBaseinfoDao")
    @NotNull
	public void setAirplaneBaseinfoDao(AirplaneBaseinfoDao baseDao)
	{
		this.airplaneBaseinfoDao = baseDao;
		setBaseDao(this.airplaneBaseinfoDao);
	}
	
/*
 	@PostConstruct
    public void init() {
        
    }
 	
 */
	@Override
    @Transactional(propagation=Propagation.REQUIRED) 
	public JSONArray listAirplaneBaseinfosAsJson(
            String[] fields,
            Map<String, Object> filterMap, PageDesc pageDesc){
			
		  return null;
	}

	@Override
	public JSONArray listDb(Map<String, Object> filterMap, PageDesc pageDesc) {
		return airplaneBaseinfoDao.listDb(filterMap,pageDesc);
	}
	
	@Override
	public AirplaneBaseinfo getAirplaneBaseinfoByCcxlh(String ccxlh) {
		// TODO Auto-generated method stub
		return airplaneBaseinfoDao.getAirplaneBaseinfoByCcxlh(ccxlh);
	}
	
	@Override
	public JSONArray getFjyjqlList(Map<String, Object> filterMap, PageDesc pageDesc) {
		if(filterMap.containsKey("nf") && StringUtils.isNotBlank(filterMap.get("nf").toString())) {
			String nf = filterMap.get("nf").toString();
			if(nf.equals("1")) {
				filterMap.put("nf", 5);
			} else if (nf.equals("2")) {
				filterMap.put("nf", 10);
			} else if (nf.equals("3")) {
				filterMap.put("nf", 15);
			} else {
				filterMap.remove("nf");
			} 
		}
		JSONArray jsonArray = airplaneBaseinfoDao.getFjyjqlList(filterMap, pageDesc);
		int index = 1;
		for(int i = 0 ; i<jsonArray.size() ; i++ ) {
			JSONObject obj = jsonArray.getJSONObject(i);
			if(i == 0) {
				obj.put("xh", index);
			} else if(obj.getString("nf").equals(jsonArray.getJSONObject(i-1).getString("nf"))) {
				index++;
				obj.put("xh", index);
			} else {
				index = 1;
				obj.put("xh", index);
			}
		}
		return jsonArray;
	}

	@Override
	public JSONArray getAirplaneBaseinfoList(Map<String, Object> filterMap, PageDesc pageDesc) {
		// TODO Auto-generated method stub
		return airplaneBaseinfoDao.getAirplaneBaseinfoList(filterMap, pageDesc);
	}

	@Override
	public JSONArray getAirplaneBaseinfoListNew(Map<String, Object> filterMap, PageDesc pageDesc) {
		return airplaneBaseinfoDao.getAirplaneBaseinfoListNew(filterMap, pageDesc);
	}

	@Override
	public void insertFlow(Long flowInstId, String a, String type) {
		// TODO Auto-generated method stub
		airplaneBaseinfoDao.insertFlow(flowInstId, a, type);
	}

	@Override
	public void insertFlowLog(String id, Long flowInstId, Long nodeInstId, String unitCode, String userCode,
			Date transIdea, String nodeName, String nodeCode) {
		// TODO Auto-generated method stub
		airplaneBaseinfoDao.insertFlowLog(id, flowInstId, nodeInstId, unitCode, userCode, transIdea, nodeName, nodeCode);
	}

	
}

